import { createWebHistory, createRouter } from 'vue-router';
import Home from '@/pages/Home.vue';
import Login from '@/pages/Search.vue';
import NotFound from '@/pages/404.vue';
import SearchHome2 from '@/pages/Search.vue';
import SearchHomeNew from '@/pages/SearchNew.vue';
import SearchHome from '@/pages/SearchHome.vue';
import SearchHome1 from '@/pages/SearchHome.vue';

const router = createRouter({
	history: createWebHistory(),
	routes: [
		{
			path: '/',
			component: SearchHome,
		},
		{
			path: '/test',
			component: SearchHomeNew,
		},
		{
			path: '/login',
			component: Login,
		},
		{
			path: '/404',
			component: NotFound,
		},
		{
			path: '/search1',
			component: SearchHome,
		},
		{
			path: '/search',
			component: SearchHome2,
		},
	],
});

// 添加全局路由前置守卫
router.beforeEach((to, _from, next) => {
	if (to.path !== '/404' && !to.matched.length) {
		// 不匹配的路由重定向到/404
		next('/404');
	} else {
		next();
	}
});

export default router;
